package ${MsgPackage};

import java.io.IOException;
<#if BeanBeanList?size!=0>
	<#list BeanBeanList as beanBean>
	<#if beanBean.list == "true">
import java.util.ArrayList;
import java.util.List;
	<#break>
	</#if>
	</#list>
</#if>

import ${LogicalPackage}.${MsgName}Logical;
import com.myapp.msg.ann.MsgDefine;
import com.myapp.msg.base.BaseMsg;
import com.myapp.msg.type.MsgPermission;

<#if BeanBeanList?size!=0>
	<#list BeanBeanList as beanBean>
import ${beanBean.clazz};
	</#list>
</#if>

/**
 * 文件名：${MsgName}Msg.java
 * <p>
 * 功能：${MsgComment}
 * <p>
 * 版本：1.0.0
 * <p>
 * 作者：Builderd by AppTools
 * <p>
 */
@MsgDefine(id = ${MsgId}, name = "${MsgName}", permission = MsgPermission.${MsgPermission}, logicalClass = ${MsgName}Logical.class)
public class ${MsgName}Msg extends BaseMsg {

	public ${MsgName}Msg(){
	}

<#if FieldBeanList?size!=0>
	<#list FieldBeanList as field>
	//${field.comment}
	<#if field.type == "int">
	private ${field.type} ${field.name} = 0;
	</#if>
	<#if field.type == "long">
	private ${field.type} ${field.name} = 0;
	</#if>
	<#if field.type == "String">
	private ${field.type} ${field.name} = null;
	</#if>
	<#if field.type == "boolean">
	private ${field.type} ${field.name} = false;
	</#if>
	<#if field.type == "byte">
	private ${field.type} ${field.name} = 0;
	</#if>
	<#if field.type == "short">
	private ${field.type} ${field.name} = 0;
	</#if>
			
	</#list>
</#if>
<#if BeanBeanList?size!=0>
	<#list BeanBeanList as beanBean>
	<#if beanBean.list == "true">
	private List<${beanBean.clazzShort}> ${beanBean.name}=null;
	
	<#else>
	private ${beanBean.clazzShort} ${beanBean.name}=null;
	
	</#if>
	</#list>
</#if>
<#if FieldBeanList?size!=0>
	<#list FieldBeanList as field>
	//${field.comment}的get方法
	public ${field.type} get${field.name?cap_first}() {
		return ${field.name};
	}

	//${field.comment}的set方法
	public void set${field.name?cap_first}(${field.type} ${field.name}) {
		this.${field.name} = ${field.name};
	}
	
	</#list>
</#if>
<#if BeanBeanList?size!=0>
	<#list BeanBeanList as beanBean>
	<#if beanBean.list == "true">
	//${beanBean.comment}的get方法
	public List<${beanBean.clazzShort}> get${beanBean.clazzShort?cap_first}() {
		return ${beanBean.name};
	}

	//${beanBean.comment}的set方法
	public void set${beanBean.clazzShort?cap_first}(List<${beanBean.clazzShort}> ${beanBean.name}) {
		this.${beanBean.name} = ${beanBean.name};
	}	
	<#else>
	//${beanBean.comment}的get方法
	public ${beanBean.clazzShort} get${beanBean.clazzShort?cap_first}() {
		return ${beanBean.name};
	}

	//${beanBean.comment}的set方法
	public void set${beanBean.clazzShort?cap_first}(${beanBean.clazzShort} ${beanBean.name}) {
		this.${beanBean.name} = ${beanBean.name};
	}
	</#if>
	
	</#list>
</#if>
	@Override
	public void read() throws IOException {
		//读取Field
<#if FieldBeanList?size!=0>
	<#list FieldBeanList as field>
		//读取${field.comment}
		this.set${field.name?cap_first}(this.read${field.type?cap_first}());
		
	</#list>
</#if>
		//读取Bean
<#if BeanBeanList?size!=0>
	<#list BeanBeanList as beanBean>
	<#if beanBean.list == "true">
		List<${beanBean.clazzShort}> ${beanBean.name}List=new ArrayList<${beanBean.clazzShort}>();

		${beanBean.clazzShort} tmp;
		//读取list长度
		int size=this.readByte();
		//循环读取数据
		for(int i=0;i<size;i++){
			tmp=new ${beanBean.clazzShort}();
			
		<#list beanBean.fieldsBean as field>
			//读取${field.comment}
			tmp.set${field.name?cap_first}(this.read${field.type?cap_first}());
			
		</#list>
			${beanBean.name}List.add(tmp);
		}
		this.set${beanBean.clazzShort?cap_first}(${beanBean.name}List);
		
	<#else>
		${beanBean.name}=new ${beanBean.clazzShort}();
		
		<#list beanBean.fieldsBean as field>
		//读取${field.comment}
		${beanBean.name}.set${field.name?cap_first}(this.read${field.type?cap_first}());
			
		</#list>
		this.set${beanBean.clazzShort?cap_first}(${beanBean.name});
	</#if>
	
	</#list>
</#if>
	}
	
	@Override
	public void write() throws IOException {
<#if FieldBeanList?size!=0>
	<#list FieldBeanList as field>
		//写入${field.comment}
		this.write${field.type?cap_first}(this.get${field.name?cap_first}());
		
	</#list>
</#if>
<#if BeanBeanList?size!=0>
	<#list BeanBeanList as beanBean>
	<#if beanBean.list == "true">
		//写入list长度
		this.writeByte((byte)${beanBean.name}.size());
		//循环写入数据
		for(${beanBean.clazzShort} beanBean:${beanBean.name}){
			<#list beanBean.fieldsBean as field>
			//写入${field.comment}
			this.write${field.type?cap_first}(beanBean.get${field.name?cap_first}());
			
			</#list>
		}
	<#else>
	<#list beanBean.fieldsBean as field>
		//写入${field.comment}
		this.write${field.type?cap_first}(${beanBean.name}.get${field.name?cap_first}());
		
	</#list>
	</#if>
	
	</#list>
</#if>
	}
}
